import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class Test_Window_Swich():
    def setup(self):
        #这段重复利用高可以进行封装
        self.driver =webdriver.Chrome()
        self.driver.maximize_window()

    def test_window_handle(self):
        self.driver.get('https://www.baidu.com/')
        windowsall = self.driver.window_handles
        window1 = self.driver.current_window_handle
        self.driver.find_element(By.ID,'s-top-loginbtn').click()
        time.sleep(3)
        #print(self.driver.current_window_handle)
        self.driver.find_element(By.ID,'TANGRAM__PSP_11__regLink').click()
        time.sleep(5)
        #print(self.driver.current_window_handle)
        #print(self.driver.window_handles)
        self.driver.switch_to_window(windowsall[-1]) #切换到列表中第2个窗口
        #self.driver.find_element(By.XPATH,'//*[@id="TANGRAM__PSP_4__userName"]').send_keys('alitest111')
        self.driver.switch_to_window(window1)  #切换回登录的窗口
        self.driver.find_element(By.ID,'TANGRAM__PSP_4__closeBtn').click() #点击关闭按钮
        time.sleep(4)
        self.driver.find_element(By.ID, 's-top-loginbtn').click()
